m = eval(input())
n = eval(input())
for i in range(m,n + 1):
    s = 0
    d = 0
    if i > 10:
        for j in range(2,i):
            if i % j == 0:
                s = s + 1
        if s == 0:
            a = int(str(i)[::-1])
            if a == i:
                continue
            for k in range(2,a):
                if a % k ==0:
                    d = d + 1
            if d == 0:
                print(i)